#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
void solve()
{
    int n;
    vector<int>a(n);
    vector<int>b(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> b[i];
    }
    ll num1 = 0, num2 = 0;
    if (a[0] >= b[0])
    {
        num1 = a[0];
        num2 = b[0];
        for (int i = 1; i < n; ++i)
        {
            num1 = num1 * 10 + min(a[i], b[i]);
            num2 = num2 * 10 + max(a[i], b[i]);
        }
    }
    cout << num1 * num2 << endl;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}